package com.pc.web.cart;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.pc.web.goods.GoodsBeans;

@Controller
public class CartController {
	@Autowired private CartDao dao;
	@Autowired private CartService service;
	
	//장바구니에 담기
	@RequestMapping(value = "/cart/insert", method = RequestMethod.GET)
	public String insert(CartBeans beans){
		dao.insert(beans);
		return "/cart/cart";	
	}
	//리스트 출력
	@RequestMapping(value = "/cart/list", method = RequestMethod.GET)
	public String list(CartBeans beans, Model model, HttpServletRequest request){
		List<CartBeans> list = service.list(beans, request);
		model.addAttribute("listBean", list);
		return "/cart/cart";
	}
	//장바구니에 담고 리스트 출력
	@RequestMapping(value = "/cart/write", method = RequestMethod.GET)
	public String write(CartBeans beans, Model model, HttpServletRequest request){
		int insert = service.insert(beans, request);
		List<CartBeans> list = service.list(beans, request);
		model.addAttribute("listBean", list);
		model.addAttribute("insertOK", insert);
		return "/cart/cart";
	}
	//장바구니 수정하고 리스트 출력
	@RequestMapping(value = "/cart/update", method = RequestMethod.GET)
	public String update(CartBeans beans, Model model, HttpServletRequest request){
		int update = service.update(beans);
		List<CartBeans> list = service.list(beans, request);
		model.addAttribute("listBean", list);
		model.addAttribute("updateOK", update);
		return "/cart/cart";
	}
	//장바구니 삭제하고 리스트출력
	@RequestMapping(value = "/cart/delete", method = RequestMethod.GET)
	public String delete(CartBeans beans, Model model, HttpServletRequest request){
		int delete = service.delete(beans);
		List<CartBeans> list = service.list(beans, request);
		model.addAttribute("listBean", list);
		model.addAttribute("deleteOK", delete);
		return "/cart/cart";
	}
}
